from edit_menu import edit_menu

class mediator_fake :
    def __init__ ( self ) :
        self . _edit_menu = None
        self . _call_history = [ ]
        self . _hide_menu = False
        self . _configure_title_text_for_menu = None
        self . _configure_next_row_for_menu = [ ]
        self . _continue = False
        self . _localization_edit_menu_continue = None
        self . _localization_edit_menu_return_to_main_menu = None
        self . _localization_edit_menu_save = None
        self . _localization_edit_menu_save_as = None
        self . _localization_edit_menu_title = None
        self . _key_escape_counter = None
    def show_menu ( self ) :
        self . _call_history += [ mediator_fake . show_menu ]
    def hide_menu ( self ) :
        self . _hide_menu = True
    def configure_title_text_for_menu ( self , title_text ) :
        self . _call_history += [ mediator_fake . configure_title_text_for_menu ]
        self . _configure_title_text_for_menu = title_text
    def configure_next_row_for_menu ( self , row_text , row_callback ) :
        self . _call_history += [ mediator_fake . configure_next_row_for_menu ]
        self . _configure_next_row_for_menu += [ [ row_text , row_callback ] ]
    def on_edit_menu_continue ( self ) :
        self . _continue = True
    def on_edit_menu_return_to_main_menu ( self ) :
        pass
    def on_edit_menu_save ( self ) :
        pass
    def on_edit_menu_save_as ( self ) :
        pass
    def localization_edit_menu_continue ( self ) :
        return self . _localization_edit_menu_continue
    def localization_edit_menu_return_to_main_menu ( self ) :
        return self . _localization_edit_menu_return_to_main_menu
    def localization_edit_menu_save ( self ) :
        return self . _localization_edit_menu_save
    def localization_edit_menu_save_as ( self ) :
        return self . _localization_edit_menu_save_as
    def localization_edit_menu_title ( self ) :
        return self . _localization_edit_menu_title
    def key_escape_counter_request ( self ) :
        self . _edit_menu . key_escape_counter_reply ( self . _key_escape_counter )

class edit_menu_tests :
    'edit_menu'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _edit_menu = edit_menu ( self . _mediator )
        self . _mediator . _edit_menu = self . _edit_menu
    #
    # show_edit_menu
    #
    def test_show_edit_menu_show_menu ( self ) :
        self . _edit_menu . show_edit_menu ( )
        self . _test . assume_equal ( self . _mediator . _call_history [ - 1 : ] , [ mediator_fake . show_menu ] )
    def test_show_edit_menu_configure_title_text_for_menu ( self ) :
        self . _mediator . _localization_edit_menu_title = 'my title'
        self . _edit_menu . show_edit_menu ( )
        self . _test . assume_equal ( self . _mediator . _configure_title_text_for_menu , 'my title' )
    def test_show_main_menu_configure_next_row_for_menu ( self ) :
        self . _mediator . _localization_edit_menu_continue = 'my continue'
        self . _mediator . _localization_edit_menu_save = 'my save'
        self . _mediator . _localization_edit_menu_save_as = 'my save as'
        self . _mediator . _localization_edit_menu_return_to_main_menu = 'my return'
        self . _edit_menu . show_edit_menu ( )
        self . _test . assume_equal ( self . _mediator . _configure_next_row_for_menu ,
            [ [ 'my continue' , self . _mediator . on_edit_menu_continue ]
            , [ 'my save' , self . _mediator . on_edit_menu_save ]
            , [ 'my save as' , self . _mediator . on_edit_menu_save_as ]
            , [ 'my return' , self . _mediator . on_edit_menu_return_to_main_menu ]
            ] )
    #
    # hide_edit_menu
    #
    def test_hide_edit_menu_hide_menu ( self ) :
        self . _edit_menu . hide_edit_menu ( )
        self . _test . assume_true ( self . _mediator . _hide_menu )
    #
    # on_key_escape
    #
    def test_on_key_escape_edit_menu_continue ( self ) :
        self . _mediator . _key_escape_counter = 'my old counter'
        self . _edit_menu . show_edit_menu ( )
        self . _mediator . _key_escape_counter = 'my new counter'
        self . _edit_menu . on_key_escape ( )
        self . _test . assume_true ( self . _mediator . _continue )
    def test_on_key_escape_after_hide ( self ) :
        self . _mediator . _key_escape_counter = 'my old counter'
        self . _edit_menu . show_edit_menu ( )
        self . _mediator . _key_escape_counter = 'my new counter'
        self . _edit_menu . hide_edit_menu ( )
        self . _edit_menu . on_key_escape ( )
        self . _test . assume_false ( self . _mediator . _continue )
    def test_on_key_escape_before_show ( self ) :
        self . _edit_menu . on_key_escape ( )
        self . _test . assume_false ( self . _mediator . _continue )
    def test_on_key_escape_after_show_with_same_counter ( self ) :
        self . _mediator . _key_escape_counter = 'my counter'
        self . _edit_menu . show_edit_menu ( )
        self . _edit_menu . on_key_escape ( )
        self . _test . assume_false ( self . _mediator . _continue )
